﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using DataServer.DTO;
using DataServer.Models;

namespace DataServer.Controllers
{
    public class PhongBanController : ApiController
    {
        private DataHelper _helper = new DataHelper();

        // GET api/phongban
        public IEnumerable<PhongBanDTO> Get()
        {
            return _helper.getDsPhongBan();
        }

        //For TEST only
        private void Test()
        {
            PhongBanDTO phg = new PhongBanDTO();
            phg.MAPHG = "004";
            phg.TenPHG = "Phát triển";
            phg.TRPHG = 4;
            phg.NG_NhanChuc = "11/11/2004";
            _helper.UpdatePhongBan("004", phg);

            //_helper.DeletePhongBan("004");
            //_helper.DeletePhongBan("005");
        }

        // GET api/phongban/5
        public PhongBanDTO Get(string id)
        {
            return _helper.getPhongBan(id);
        }

        // POST api/phongban
        public bool Post([FromBody]PhongBanDTO value)
        {
            return _helper.AddNewPhongBan(value);
        }

        // PUT api/phongban/5
        public bool Put(string id, [FromBody]PhongBanDTO value)
        {
            return _helper.UpdatePhongBan(id, value);
        }

        // DELETE api/phongban/5
        public bool Delete(string id)
        {
            return _helper.DeletePhongBan(id);
        }
    }
}
